{# This templates is used to display results when searching remote objects,
 # for example actors.
 #}

{#
SPDX-FileCopyrightText:  2020-2021 zPlus <zplus@peers.community>
SPDX-License-Identifier: GPL-2.0-only
#}

{% if result['type'] == 'Person' %}

    <table class="table-sm table-borderless">
        <thead>
            <tr>
                <th scope="col"></th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">Name</th>
                <td>{{ result['name'] }}</td>
            </tr>
            {% if 'preferredUsername' in result %}
            <tr>
                <th scope="row">Username</th>
                <td>{{ result['preferredUsername'] }}</td>
            </tr>
            {% endif %}
            <tr>
                <th scope="row">Type</th>
                <td>{{ result['type'] }}</td>
            </tr>
        </tbody>
    </table>

    <div class="mt-3">
        <a href="{{ url_for('forgefed_ns.federation_follow', actor_uri=result['id']) }}" class="mr-2">
            Follow
        </a>
    </div>

{% elif result['type'] == 'Project' %}

    <table class="table-sm table-borderless">
        <thead>
            <tr>
                <th scope="col"></th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">Name</th>
                <td>{{ result['name'] }}</td>
            </tr>
            <tr>
                <th scope="row">Type</th>
                <td>{{ result['type'] }}</td>
            </tr>
            <tr>
            {% if 'repository' in result %}
                <th scope="row">Repositories</th>
                <td>
                {% for repository in result['repository'] %}
                    <a href="{{ url_for('forgefed_ns.federation_search', uri=repository) }}" class="mr-2">
                        {{ repository }}
                    </a>
                {% endfor%}
                </th>
            {% endif %}
            </tr>
            <tr>
            {% if 'tickettracker' in result %}
                <th scope="row">Ticket Tracker</th>
                <td>
                {% for tickettracker in result['tickettracker'] %}
                    <a href="{{ url_for('forgefed_ns.federation_search', uri=tickettracker) }}" class="mr-2">
                        {{ tickettracker }}
                    </a>
                {% endfor%}
                </th>
            {% endif %}
            </tr>
        </tbody>
    </table>

{% elif result['type'] == 'Repository' %}

    <table class="table-sm table-borderless">
        <thead>
            <tr>
                <th scope="col"></th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">Name</th>
                <td>{{ result['name'] }}</td>
            </tr>
            {% if 'preferredUsername' in result %}
            <tr>
                <th scope="row">Username</th>
                <td>{{ result['preferredUsername'] }}</td>
            </tr>
            {% endif %}
            <tr>
                <th scope="row">Type</th>
                <td>{{ result['type'] }}</td>
            </tr>
            {% if 'project' in result %}
            <tr>
                <th scope="row">Project</th>
                <td>
                    <a href="{{ url_for('forgefed_ns.federation_search', uri=result['project']) }}" class="mr-2">
                        {{ result['project'] }}
                    </a>
                </td>
            </tr>
            {% endif %}
        </tbody>
    </table>

    <div class="mt-3">
        <a href="{{ url_for('forgefed_ns.federation_follow', actor_uri=result['id']) }}" class="mr-2">
            Follow
        </a>
        <a href="{{ url_for('forgefed_ns.federation_fork', repository_uri=result['id']) }}" class="mr-2">
            Fork
        </a>
    </div>

{% elif result['type'] == 'TicketTracker' %}

    <div class="mt-3">
        <table class="table-sm table-borderless">
        <thead>
            <tr>
                <th scope="col"></th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">Name</th>
                <td>{{ result['name'] }}</td>
            </tr>
            {% if 'preferredUsername' in result %}
            <tr>
                <th scope="row">Username</th>
                <td>{{ result['preferredUsername'] }}</td>
            </tr>
            {% endif %}
            <tr>
                <th scope="row">Type</th>
                <td>{{ result['type'] }}</td>
            </tr>
            {% if 'project' in result %}
            <tr>
                <th scope="row">Project</th>
                <td>
                    <a href="{{ url_for('forgefed_ns.federation_search', uri=result['project']) }}" class="mr-2">
                        {{ result['project'] }}
                    </a>
                </td>
            </tr>
            {% endif %}
        </tbody>
    </table>

    <div class="mt-3">
        <a href="{{ url_for('forgefed_ns.federation_follow', actor_uri=result['id']) }}" class="mr-2">
            Follow
        </a>

        <a href="{{ url_for('forgefed_ns.federation_submit_ticket', actor_uri=result['id']) }}" class="mr-2">
            Submit ticket
        </a>
    </div>

{% endif %}
